package mortal.game.control
{
    import Framework.MQ.*;
    import Message.Command.*;
    import Message.Public.*;
    import com.gengine.global.*;
    import com.gengine.manager.*;
    import com.mui.controls.*;
    import flash.display.*;
    import mortal.common.global.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene.events.*;
    import mortal.game.scene.modle.data.*;
    import mortal.game.scene.player.entity.*;
    import mortal.game.scene.player.item.*;
    import mortal.game.view.msgbroad.*;
    import mortal.mvc.core.*;

    public class SystemController extends Controller
    {
        private var _alert:Sprite;
        private var _levelUp:EffectPlayer;

        public function SystemController()
        {
            
        }

        override protected function initServer() : void
        {
            NetDispatcher.addCmdListener(ECmdCoreCommand._ECmdCoreKillUser, this.onKillUserHandler);
            Dispatcher.addEventListener(EventName.SocketClose, this.onSockCloseHandler);
            RolePlayer.instance.addEventListener(PlayerEvent.RoleLevelUpdate, this.onRoleLevelUpdateHandler);
            
        }

        private function onRoleLevelUpdateHandler(event:PlayerEvent) : void
        {
            if (this._levelUp)
            {
                if (LayerManager.highestLayer.contains(this._levelUp))
                {
                    LayerManager.highestLayer.removeChild(this._levelUp);
                }
                this._levelUp.stop();
            }
            else
            {
                this._levelUp = new EffectPlayer();
                this._levelUp.playTotal = 1;
            }
            if (LayerManager.highestLayer.contains(this._levelUp) == false)
            {
                LayerManager.highestLayer.addChild(this._levelUp);
            }
            this._levelUp.move(Global.stage.stageWidth / 2, Global.stage.stageHeight / 2 - 160);
            this._levelUp.load(StaticResUrl.Levelup1, ModelType.Effect, null);
            
        }

        private function onSockCloseHandler(event:DataEvent) : void
        {
            this.alert("连接已断开，请重新登陆");
            
        }

        private function onKillUserHandler(param1:MessageBlock) : void
        {
            var _loc_3:IssmNoticItem = null;
            var _loc_2:* = param1.messageBase as SAttribute;
            switch(_loc_2.value)
            {
                case EKickOutReason._EKickOutReasonByCloseGate:
                {
                    this.alert("重启网关服务器！！");
                    break;
                }
                case EKickOutReason._EKickOutReasonByCloseCell:
                {
                    this.alert("重启CELL服务器！！");
                    break;
                }
                case EKickOutReason._EKickOutReasonByCloseGateMgr:
                {
                    this.alert("重启网关服务器！！");
                    break;
                }
                case EKickOutReason._EKickOutReasonByCloseInterMgr:
                {
                    this.alert("共用服务器关闭！！");
                    break;
                }
                case EKickOutReason._EKickOutReasonByCloseDbApp:
                {
                    this.alert("数据库关闭！！");
                    break;
                }
                case EKickOutReason._EKickOutReasonByElseLogin:
                {
                    this.alert("你的账号在其他客户端登录！！");
                    break;
                }
                case EKickOutReason._EKickOutReasonByIssmThreeHour:
                {
                    this.alert("您已进入不健康游戏时间，请您暂时离开游戏进行适\r当休息和运动，合理安排您的游戏时间，点击确定退出游戏。");
                    _loc_3 = new IssmNoticItem();
                    _loc_3.updateData("您已进入不健康游戏时间，请您暂时离开游戏进行适\r当休息和运动，合理安排您的游戏时间，点击确定退出游戏。");
                    MsgManager._msgIssmImpl.addItem(_loc_3);
                    break;
                }
                case EKickOutReason._EKickOutReasonByIssmOfflineTimeLessFiveHour:
                {
                    this.alert("您的累计下线时间不满5小时，为了保证您\r能正常游戏，请您稍后登陆。");
                    _loc_3 = new IssmNoticItem();
                    _loc_3.updateData("您的累计下线时间不满5小时，为了保证您\r能正常游戏，请您稍后登陆。");
                    MsgManager._msgIssmImpl.addItem(_loc_3);
                    break;
                }
                default:
                {
                    break;
                }
            }
            
        }

        private function alert(param1:String, param2:uint = 4) : void
        {
            if (this._alert == null)
            {
                Alert.mode = Alert.Mode_Simple;
                this._alert = Alert.show(param1, null, param2, null, this.closeHandler);
            }
            
        }

        private function closeHandler(param1:int) : void
        {
            this._alert = null;
            if (param1 == Alert.OK)
            {
                if (ParamsConst.instance.actimUrl != null && ParamsConst.instance.actimUrl != "")
                {
                    BrowerManager.instance.getUrl(ParamsConst.instance.actimUrl);
                }
            }
            
        }

    }
}
